package cn.dt70.services.impl;

import cn.dt70.dao.user.UserMapper;
import cn.dt70.pojo.DevUser;
import cn.dt70.services.UserService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {
    private static final Logger logger=Logger.getLogger( UserServiceImpl.class );
    @Resource
    private UserMapper userMapper;
//    用户登录
    @Override
    public boolean dologin(String devCode, String devPassword){
        boolean result =false;
        try {
            DevUser user = userMapper.qryUserByCode(devCode);
            if (null == user) {
                logger.debug("UserServiceImpl.doLogin 查询用户为空!");
            } else {
                if (!devPassword.equals(user.getDevPassword())) {
                    logger.debug("UserServiceImpl.doLogin 输入的账号和密码不匹配!");
                } else {
                    logger.debug("UserServiceImpl.doLogin 登陆成功>>>>>!");
                    result = true;
                }
            }
        } catch (Exception e) {
            logger.error("UserServiceImpl.doLogin 异常:" + e.getMessage());
        }
        return result;
    }

//根据账号查找用户
    @Override
    public DevUser qryUserByCode(String devCode) {
        DevUser user = new DevUser();
        try {
             user = userMapper.qryUserByCode( devCode );
            if(user == null){
                logger.debug("UserServiceImpl.qryUserByCode 查询为空==");
                user = new DevUser();
            }else{
                logger.debug("UserServiceImpl.qryUserByCode 查询成功！");
            }
        } catch (Exception e) {
            logger.debug("UserServiceImpl.qryUserByCode 异常"+e.getMessage());
        }

        return user;
    }
}
